home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Griffith 0.9.8 / griffith-0.9.8-win32.exe / {app} / lib / plugins / movie / PluginMovieFilmeVonAZ.py < prev    next >
Text File  |  2008-11-17  |  9KB  |  266 lines

  1. # -*- coding: UTF-8 -*-
  2.  
  3. __revision__ = '$Id: PluginMovieFilmeVonAZ.py 1040 2008-11-15 21:13:49Z mikej06 $'
  4.  
  5. # Copyright (c) 2006-2007 Michael Jahn
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU Library General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  20.  
  21. # You may use and distribute this software under the terms of the
  22. # GNU General Public License, version 2 or later
  23.  
  24. import gutils
  25. import movie
  26. import string
  27. import re
  28.  
  29. plugin_name = "FilmeVonA-Z.de"
  30. plugin_description = "FILMEvonA-Z.de"
  31. plugin_url = "www.filmevona-z.de"
  32. plugin_language = _("German")
  33. plugin_author = "Michael Jahn"
  34. plugin_author_email = "<mikej06@hotmail.com>"
  35. plugin_version = "1.3"
  36.  
  37. class Plugin(movie.Movie):
  38.     def __init__(self, id):
  39.         self.encode='utf-8'
  40.         self.movie_id = id
  41.         self.url = 'http://www.filmevona-z.de/filmsuche.cfm?sucheNach=Titel&wert=' + str(self.movie_id)
  42.  
  43.     def get_image(self):
  44.         self.image_url = gutils.trim(self.page, 'ProductCover=', '"')
  45.         if not self.image_url == '':
  46.             self.image_url = "http://www.filmevona-z.de/" + self.image_url
  47.  
  48.     def get_o_title(self):
  49.         self.o_title = string.capwords(
  50.             gutils.clean(gutils.after(
  51.             self.regextrim(self.page, '"[ \t]+class="text_ergebniss_titel"', '[ \t]+[(]Originaltitel[)]'), '</a>')))
  52.         if self.o_title == '':
  53.             self.o_title = gutils.after(gutils.trim(self.page, 'sucheNach=titel', '</a>'), '>')
  54.  
  55.     def get_title(self):
  56.         self.title = gutils.after(gutils.trim(self.page, 'sucheNach=titel', '</a>'), '>')
  57.  
  58.     def get_director(self):
  59.         self.director = gutils.after(gutils.trim(self.page, '(Regie)', '</a>'), '>')
  60.  
  61.     def get_plot(self):
  62.         self.plot = gutils.after(self.regextrim(self.page, '[(]Darsteller[)]', '</[pP]>'), '<p>')
  63.  
  64.     def get_year(self):
  65.         self.year = gutils.after(gutils.trim(self.page, 'sucheNach=produktionsjahr', '</a>'), '>')
  66.  
  67.     def get_runtime(self):
  68.         self.runtime = gutils.trim(self.page, 'Länge: ', ' Minuten')
  69.  
  70.     def get_genre(self):
  71.         elements = string.split(self.page, 'sucheNach=genre')
  72.         if (elements[0]<>''):
  73.             elements[0] = ''
  74.             self.delimiter = ''
  75.             self.genre = ''
  76.             for element in elements:
  77.                 if (element <> ''):
  78.                     self.genre += self.delimiter + gutils.trim(element, '>', '</a>')
  79.                     self.delimiter = ", "
  80.  
  81.     def get_cast(self):
  82.         self.cast = self.regextrim(self.page, '[(]Darsteller[)]', '(<[pP]>|<br><span[^>]+>)')
  83.         self.cast = gutils.clean(self.cast)
  84.         self.cast = self.cast.replace(' als ', _(' as '))
  85.         self.cast = re.sub('( \t|\t|\r|\n)', '', self.cast)
  86.         self.cast = self.cast.replace(', ', '\n')
  87.         self.cast = self.cast.replace(',', '')
  88.  
  89.     def get_classification(self):
  90.         self.classification = self.regextrim(self.page, 'FSK:[ ]+', '[,;]')
  91.  
  92.     def get_studio(self):
  93.         self.studio = gutils.after(gutils.trim(self.page, 'sucheNach=produktionsfirma', '</a>'), '>')
  94.  
  95.     def get_o_site(self):
  96.         self.o_site = ''
  97.  
  98.     def get_site(self):
  99.         self.site = 'http://www.filmevona-z.de/filmsuche.cfm?sucheNach=Titel&wert=' + self.movie_id;
  100.  
  101.     def get_trailer(self):
  102.         self.trailer = ''
  103.  
  104.     def get_country(self):
  105.         self.country = gutils.after(gutils.trim(self.page, 'sucheNach=produktionsland', '</a>'), '>')
  106.  
  107.     def get_rating(self):
  108.         self.rating = 0
  109.         
  110.     def regextrim(self,text,key1,key2):
  111.         obj = re.search(key1, text)
  112.         if obj is None:
  113.             return ''
  114.         else:
  115.             p1 = obj.end()
  116.         obj = re.search(key2, text[p1:])
  117.         if obj is None:
  118.             return ''
  119.         else:
  120.             p2 = p1 + obj.start()
  121.         return text[p1:p2]
  122.  
  123. class SearchPlugin(movie.SearchMovie):
  124.     def __init__(self):
  125.         self.original_url_search    = "http://www.filmevona-z.de/filmsuche.cfm?sucheNach=Titel&wert="
  126.         self.translated_url_search    = "http://www.filmevona-z.de/filmsuche.cfm?sucheNach=Titel&wert="
  127.         self.encode='utf-8'
  128.  
  129.     def search(self,parent_window):
  130.         self.open_search(parent_window)
  131.         # used for looking for subpages
  132.         tmp_page = gutils.trim(self.page, "Treffer-Seite", "chste Seite")
  133.         elements = string.split(tmp_page, '" class="text_navi">')
  134.         # first results
  135.         tmp_page = gutils.after(gutils.trim(self.page,"Alle Treffer aus der Kategorie", "Treffer-Seite"), "Titel:")
  136.         # look for subpages
  137.         for element in elements:
  138.             element = gutils.before(element, "</a>")
  139.             try:
  140.                 tmp_element = int(element)
  141.             except:
  142.                 tmp_element = 1
  143.             if (tmp_element <> 1):
  144.                 self.url = "http://www.filmevona-z.de/filmsuche.cfm?sucheNach=Titel¤tPage=" + str(tmp_element) + "&wert="
  145.                 self.open_search(parent_window)
  146.                 tmp_page2 = gutils.trim(self.page,"Alle Treffer aus der Kategorie", "Treffer-Seite")
  147.                 tmp_page = tmp_page + tmp_page2
  148.         self.page = tmp_page
  149.  
  150.         return self.page
  151.  
  152.     def get_searches(self):
  153.         elements = string.split(self.page,'class="text_ergebniss_titel"')
  154.         i = 0
  155.         while i < len(elements) - 1:
  156.             id_part = elements[i]
  157.             i = i + 1
  158.             text_part = elements[i]
  159.             i = i + 1
  160.             self.ids.append(gutils.trim(id_part, 'filmsuche.cfm?wert=', '&'))
  161.             self.titles.append(gutils.strip_tags(
  162.                         gutils.trim(text_part, '>', '</a>') + ' (' +
  163.                         string.capwords(gutils.trim(text_part, '</a>', '(Originaltitel)')) + ', ' +
  164.                         gutils.after(gutils.trim(text_part, 'sucheNach=produktionsland', '</a>'), '>') + ', ' +
  165.                         gutils.after(gutils.trim(text_part, 'sucheNach=produktionsjahr', '</a>'), '>') +
  166.                         ')'))
  167.  
  168. #
  169. # Plugin Test
  170. #
  171. class SearchPluginTest(SearchPlugin):
  172.     #
  173.     # Configuration for automated tests:
  174.     # dict { movie_id -> [ expected result count for original url, expected result count for translated url ] }
  175.     #
  176.     test_configuration = {
  177.         'Rocky Balboa'            : [ 1, 1 ],
  178.         'Arahan'                : [ 1, 1 ],
  179.         'Ein gl├╝ckliches Jahr'    : [ 0, 0 ]
  180.     }
  181.  
  182. class PluginTest:
  183.     #
  184.     # Configuration for automated tests:
  185.     # dict { movie_id -> dict { arribute -> value } }
  186.     #
  187.     # value: * True/False if attribute should only be tested for any value
  188.     #        * or the expected value
  189.     #
  190.     test_configuration = {
  191.         '528267' : { 
  192.             'title'             : 'Rocky Balboa',
  193.             'o_title'             : 'Rocky Balboa',
  194.             'director'            : 'Sylvester Stallone',
  195.             'plot'                 : True,
  196.             'cast'                : 'A.J. Benza' + _(' as ') + 'L.C.\n\
  197. Milo Ventimiglia' + _(' as ') + 'Rocky jr.\n\
  198. Antonio Tarver' + _(' as ') + 'Mason \'The Line\' Dixon\n\
  199. Geraldine Hughes' + _(' as ') + 'Marie\n\
  200. Sylvester Stallone' + _(' as ') + 'Rocky Balboa\n\
  201. Burt Young' + _(' as ') + 'Paulie\n\
  202. Tony Burton' + _(' as ') + 'Duke',
  203.             'country'            : 'USA',
  204.             'genre'                : 'Boxerfilm',
  205.             'classification'    : 'ab 12',
  206.             'studio'            : 'Columbia Pic./ MGM/ Rogue Marble/ Revolution Studios/ Chartoff-Winkler Prod.',
  207.             'o_site'            : False,
  208.             'site'                : 'http://www.filmevona-z.de/filmsuche.cfm?sucheNach=Titel&wert=528267',
  209.             'trailer'            : False,
  210.             'year'                : 2006,
  211.             'notes'                : False,
  212.             'runtime'            : 102,
  213.             'image'                : False,
  214.             'rating'            : False
  215.         },
  216.         '26956' : { 
  217.             'title'             : 'B├╝rgschaft f├╝r ein Jahr',
  218.             'o_title'             : 'B├╝rgschaft f├╝r ein Jahr',
  219.             'director'            : 'Herrmann Zschoche',
  220.             'plot'                 : True,
  221.             'cast'                : 'Heide Kipp' + _(' as ') + 'Frau Braun\n\
  222. Jan Spitzer' + _(' as ') + 'Werner Horn\n\
  223. Monika Lennartz' + _(' as ') + 'Irmgard Behrend\n\
  224. Katrin Sa├ƒ' + _(' as ') + 'Nina\n\
  225. Ursula Werner' + _(' as ') + 'Frau M├╝ller\n\
  226. Christian Steyer' + _(' as ') + 'Heiner Menk\n\
  227. Jaecki Schwarz' + _(' as ') + 'Peter M├╝ller\n\
  228. Barbara Dittus' + _(' as ') + 'Heimleiterin',
  229.             'country'            : 'DDR',
  230.             'genre'                : 'Arbeiterfilm, Frauenfilm, Literaturverfilmung',
  231.             'classification'    : 'ab 6',
  232.             'studio'            : 'DEFA, Gruppe "Berlin"',
  233.             'o_site'            : False,
  234.             'site'                : 'http://www.filmevona-z.de/filmsuche.cfm?sucheNach=Titel&wert=26956',
  235.             'trailer'            : False,
  236.             'year'                : 1981,
  237.             'notes'                : False,
  238.             'runtime'            : 93,
  239.             'image'                : False,
  240.             'rating'            : False
  241.         },
  242.         '524017' : { 
  243.             'title'             : 'Arahan',
  244.             'o_title'             : 'Arahan Jangpung Daejakjeon',
  245.             'director'            : 'Ryoo Seung-wan',
  246.             'plot'                 : True,
  247.             'cast'                : 'Yoon So-yi' + _(' as ') + 'Wi-jin\n\
  248. Yun Ju-sang' + _(' as ') + 'Mu-woon\n\
  249. Ahn Sung-kee' + _(' as ') + 'Ja-woon\n\
  250. Jung Doo-hong' + _(' as ') + 'Heukwoon\n\
  251. Ryu Seung-beom' + _(' as ') + 'Sang-hwan',
  252.             'country'            : 'S├╝dkorea',
  253.             'genre'                : False,
  254.             'classification'    : 'ab 16',
  255.             'studio'            : 'Fun and Happiness/ Good Movie',
  256.             'o_site'            : False,
  257.             'site'                : 'http://www.filmevona-z.de/filmsuche.cfm?sucheNach=Titel&wert=524017',
  258.             'trailer'            : False,
  259.             'year'                : 2004,
  260.             'notes'                : False,
  261.             'runtime'            : 108,
  262.             'image'                : False,
  263.             'rating'            : False
  264.         }
  265.     }
  266.